Repository navigation
feat: GSM Secrets - Keep new secrets in an optional store - #474
yuechao-qin wants to merge 5 commits into
Conversation
|
@yuechao-qin How about replacing the whole |
…s on first use SecretStore is an abstract base class whose subclass methods are wrapped to move the caller's rows out of the secret table first. Replaces the storage-type hook: no storage flag, no 503 handler.
Launches read the table first, then the store, without writing; get no longer takes a session.
…o the store SecretStore is a Protocol again; no move on use. PUT/DELETE lock the row only with a store; DELETE also removes a store copy; list reads the store.
|
|
||
| def create(self, *, secret: StoredSecret) -> StoredSecret: | ||
| """Saves a new secret and returns it without its value; raises `errors.ItemAlreadyExistsError` if it exists.""" | ||
| ... |
| Keeps the stored `created_at` and name, and the stored description when `description` is None. | ||
| Raises `errors.ItemNotFoundError` when there is no such secret. | ||
| """ | ||
| ... |
|
|
||
| def get(self, *, user_id: str, secret_name: str) -> str | None: | ||
| """Returns the secret's latest value, or None when there is no such secret.""" | ||
| ... |
|
|
||
| def list_secrets(self, *, user_id: str) -> list[StoredSecret]: | ||
| """Returns the user's secrets, without values.""" | ||
| ... |
|
|
||
| def delete(self, *, user_id: str, secret_name: str) -> None: | ||
| """Deletes the secret and all its values; raises `errors.ItemNotFoundError` when there is none.""" | ||
| ... |
There was a problem hiding this comment.
Maybe, secret_interfaces.py? I already see problematic cases in the code: secret_store: secret_store.SecretStore
| """Returns the secret's latest value, or None when there is no such secret.""" | ||
| ... | ||
|
|
||
| def list_secrets(self, *, user_id: str) -> list[StoredSecret]: |
There was a problem hiding this comment.
Naming consistency: This is the only method with _secrets suffix...
We could either call this one list or add suffixes to other ones.
I think list is fine. I've seen it used in other libraries. Yes, we'll have to be careful about using he builtin list in signatures, but only for this class. Which does not have any list. So, it should be fine.
What
Secrets can now live outside the database: give
setup_routesasecret_store, and new secrets go to it. A secret already in thesecrettable stays there and works as today until it is moved. Without a store, nothing changes.POST /api/secrets/create(409 if the store has it)PUT /api/secrets/{name}update(404 if missing); an empty description keeps the stored one, as todayDELETE /api/secrets/{name}delete(404 if missing)GET /api/secrets/list_secretsSecretStoreis aProtocolwithcreate,update,get,list_secretsanddelete; a store never sees the session or the table.StoredSecretcarries the table's columns; itsvalueis left out of repr, so a logged secret never shows it.With a store, PUT and DELETE read the row with
FOR UPDATE. The lock is on that one row (the lookup is by primary key), so a bulk move of the same row either finishes first or waits. DELETE also deletes the store's copy, in case a bulk move stopped after copying the row but before deleting it; otherwise a deleted secret could come back.Why
Secret values sit in the database as plain text, so anyone who can read the table or a backup can read every secret. This lets a deployment keep them in a store of its choice, and the backend stays free of any provider.
The routes never move anything, so a request does only what it says. The next two PRs read from the store at launch and add an admin route that moves the remaining rows in bulk; until that runs, secrets still in the table are missing from the list but keep working everywhere else.
Verification
tests/test_secret_store.py(15 tests, fake in-memory store): no store keeps the table behaviour; create writes no row; create of a name still in the table is 409 and changes nothing; update of a row updates it in place; update of a stored secret keeps itscreated_atand description; an empty description keeps the stored one; update of a missing secret is 404; delete of a row, of a row with a leftover store copy, and of a stored secret, then 404; list reads only the store; the row is locked with a store and not without; the value never shows in repr;setup_routespasses the store through (200, 409, list).tests/instrumentation/test_execution_tracing.pyfail onmaster. Also passes on Python 3.14.